const dayjs = require("dayjs");

Component({
    properties: {
        isShowTitle: {
            type: Boolean,
            value: false
        },
        isShowAll: {
            type: Boolean,
            value: false
        },
        title: {
          type: String,
          value: '订单详情'
        },
        allText: {
            type: String,
            value: '查看全部'
        },
        dataSource: {
            type: Array
        },
        isShowExport: {
            type: Boolean,
            value: false
        }
    },
    observers: {
      'dataSource': function (dataSource) {
          this.transFormList(dataSource)
      }
    },
    data: {
        itemList: [],
        orderTitleList: []
    },
    methods: {
        // 点击全部订单
        handleClickAll() {
            this.triggerEvent('onrouter')
        },
        handleClickExport() {
            this.triggerEvent('export')
        },
        transFormList(dataSource) {
            if (dataSource) {
                const titleList = this.data.dataSource.map((item) => {
                    return {
                        id: item.taskId,
                        title: item.taskId
                    }
                })
                const nameList = this.data.dataSource.map(item => item.name)
                const statusList = this.data.dataSource.map(item => {
                    let itemText = ''
                    if (item.status == 1) {
                        itemText = '输入订单'
                    } else if (item.status == 2) {
                        itemText = '输入订单'
                    } else if (item.statusem == 3) {
                        itemText = '计算中'
                    } else if (item.status == 4) {
                        itemText = '装车中'
                    } else if (item.status == 5) {
                        itemText = '补包中'
                    } else if (item.status == 6) {
                        itemText = '完成'
                    } else if (item.status == 7) {
                        itemText = '装车取消'
                    }
                    return itemText
                })
                const carList = this.data.dataSource.map(item => item.licenseNo)
                const startTimeList = this.data.dataSource.map(item => item.startTime)
                const endTimeList = this.data.dataSource.map(item => item.endTime)
                const countPackageList = this.data.dataSource.map(item => item.amount)
                const countTonList = this.data.dataSource.map(item => item.ton)
                const startLoadingTimeList = this.data.dataSource.map(item => {
                    let str = ''
                    if (item.startLoadingTime) {
                        str = dayjs(item.startLoadingTime).format('YYYY-MM-DD HH:mm:ss')
                    } else {
                        str = '暂无'
                    }
                    return str
                })
                const itemList = [
                    {
                        name: "车道",
                        list: nameList
                    },
                    {
                        name: '完成情况',
                        list: statusList
                    },
                    {
                        name: "完成数量（包）",
                        list: countPackageList
                    },
                    {
                        name: "完成数量（吨）",
                        list: countTonList
                    },
                    {
                        name: "车牌",
                        list: carList
                    },
                    {
                        name: "订单开始时间",
                        list: startTimeList
                    },
                    {
                        name: "开始装车时间",
                        list: startLoadingTimeList
                    },
                    {
                        name: "结束时间",
                        list: endTimeList
                    },
                   
                ]
                this.setData({
                    itemList,
                    orderTitleList: titleList
                })
            }
        },
    }
});
